package com.ccjq.shosestore.web.controller.member;

import com.ccjq.shosestore.member.service.UserService;
import com.ccjq.shosestore.member.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 用户名校验
 */
public class UserExistCheckServlet extends HttpServlet {
    private UserService userService = new UserServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        System.out.println("========>用户名注册重名检查....");
        boolean b = userService.existx(username);
        if (b) {
            System.out.println("============>用户名 " + username + "已被注册");
        } else {
            System.out.println("==============> 用户名 " + username + "可以注册");
        }
        PrintWriter out = response.getWriter();
        String result = "{\"code\":" + b + "}";
        out.println(result);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
